package com.example.a2032.entity;

import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.Index;

import com.hyphenate.easeui.domain.EaseUser;

import java.util.ArrayList;
import java.util.List;

@Entity(tableName = "em_users",primaryKeys = {"username"},indices = {@Index(value = {"username"}, unique = true)})
public class UserEntity extends EaseUser {
    public UserEntity(){

    }

    @Ignore
    public static List<UserEntity> parseList(List<EaseUser> users) {
        List<UserEntity> entities = new ArrayList<>();
        if (users == null || users.isEmpty()) {
            return entities;
        }
        UserEntity entity;
        for (EaseUser user : users) {
            entity = parseParent(user);
            entities.add(entity);
        }
        return entities;
    }

    @Ignore
    public static UserEntity parseParent(EaseUser user) {
        UserEntity entity = new UserEntity();
        entity.setUsername(user.getUsername());
        entity.setNickname(user.getNickname());
        entity.setAvatar(user.getAvatar());
        entity.setInitialLetter(user.getInitialLetter());
        entity.setContact(user.getContact());
        return entity;
    }
}
